﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.Library;
using DataObject;
using DataObject.Cache;

namespace Event
{
    public partial class Test2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Request.IsAuthenticated)
            {
                var ident = HttpContext.Current.User.Identity as FormsIdentity;
                if (ident != null)
                {
                    try
                    {
                        FormsAuthenticationTicket ticket1 = ident.Ticket;
                        Response.Write("FormsIdentity:" + ticket1.UserData);
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                    }
                }
            }
            else if (HttpContext.Current.Session[Const.AuthenticationSessionName] != null)
            {
                Response.Write("Session:" + HttpContext.Current.Session[Const.AuthenticationSessionName].ToString());
            }
        }

        protected void btnDecryptFormsAuthTicket_Click(object sender, EventArgs e)
        {
            //Channelvn.Cached.CacheController.RemoveAll(Constants.DATA_CACHE_CATEGORY);

            //StringBuilder sb = new StringBuilder("");

            //sb.Append("<p><b>Forms Authentication Ticket Information</b></p>");
            //System.Web.Security.FormsAuthenticationTicket ticket = null;
            //try
            //{
            //    ticket = System.Web.Security.FormsAuthentication.Decrypt(txtDecrpytionTicket.Text);
            //}
            //catch (Exception ex)
            //{
            //    sb.Append(ex.Message);
            //}
            //if (ticket == null)
            //    sb.Append("<br /> System.Web.Security.FormsAuthentication.Decrypt method returned null");
            //else
            //{

            //    sb.Append("<br />&nbsp;  ticket.Name: " + ticket.Name);
            //    sb.Append("<br />&nbsp;  ticket.UserData: " + ticket.UserData);
            //    sb.Append("<br />&nbsp;  ticket.CookiePath: " + ticket.CookiePath);
            //    sb.Append("<br />&nbsp;  ticket.Expired: " + ticket.Expired.ToString());
            //    sb.Append("<br />&nbsp;  ticket.Expiration: " + ticket.Expiration);
            //    sb.Append("<br />&nbsp;  ticket.IsPersistent: " + ticket.IsPersistent);
            //    sb.Append("<br />&nbsp;  ticket.IssueDate: " + ticket.IssueDate);
            //}

            //divResults.InnerHtml = sb.ToString();
        }
    }
}